package set集合;

import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

public class treeset_demo2 {
    public static void main(String[] args) {                                         //类重写的话会就近原则优先集合定义的规则
        Set<apple> a=new TreeSet<>((o1,o2) -> o1.getWeight()-o2.getWeight()>=0?1:-1);//升序浮点型建议double.compare比较

        a.add(new apple("红富士",9.9,"红色",500));
        a.add(new apple("青苹果",19.9,"青色",400));
        a.add(new apple("毒苹果",0.9,"紫色",800));
        a.add(new apple("黄苹果",29.9,"黄色",500));
        System.out.println(a);//如果不进行排序规则则报错1.让类实现comparable 2.给集合制定排序规则
    }
}
